package com.dao.impl;

import com.dao.UserDao;
import com.domain.User;

import com.factory.OfficeFactory;import com.utils.MD5Util;

import java.util.ArrayList;

public class UserDaoImpl implements UserDao {

    private final String JM = "lhdnb";

    @Override
    public Boolean save(User user) {
        String sql = "insert into user values(null,?,?,?,?)";

        return OfficeFactory.update(sql,user.getUname(),MD5Util.getMD5Str(user.getUpwd()+JM),user.getSex(),
                user.getPhone());
    }

    @Override
    public Boolean delete(int id) {
        String sql = "delete from user where id = ?";

        return OfficeFactory.update(sql,id);
    }

    @Override
    public User selectOne(User user) {
        String sql = "select * from user where uname = ?";

        ArrayList<User> arr = OfficeFactory.select(new User(),sql, user.getUname());
        if(arr != null && arr.size() > 0) {
            return arr.get(0);
        }
        return null;
    }
}
